package LeetCode.top100;

public class LC3 {
    public static void main(String[] args) {
        LC3 instance = new LC3();
        System.out.println(instance.lengthOfLongestSubstring("abcabcbb"));
    }
    public int lengthOfLongestSubstring(String s) {
        if(s.length() == 0 || s.length() == 1){
            return s.length();
        }
        int[] arr = new int[128];
        char[] chars = s.toCharArray();
        int left = 0, right = 0, res = 0;
        for(; right < chars.length; right++){
            arr[chars[right]]++;
            res = Math.max(res, right - left);
            while(left < chars.length && arr[chars[right]] != 1){
                arr[chars[left]]--;
                left++;
            }
        }
        res = Math.max(res, right-left);
        return res;
    }
}
